package com.wky.user.controller;

import com.wky.basic.Result.JsonResult;
import com.wky.basic.exception.BusinessException;
import com.wky.user.dto.RegisterDTO;
import com.wky.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@CrossOrigin
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 手机号注册
     */
    @PostMapping("/phoneRegister")
    public JsonResult phoneRegister(@RequestBody RegisterDTO registerDTO) {
        try {
            userService.phoneRegister(registerDTO);
            return JsonResult.success();
        } catch (BusinessException e) {
            e.printStackTrace();
            return JsonResult.error(e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return JsonResult.error("系统异常");
        }
    }

    /**
     * 邮箱注册
     */
    @PostMapping("/emailRegister")
    public JsonResult emailRegister(@RequestBody RegisterDTO registerDTO) {
        try {
            userService.emailRegister(registerDTO);
            return JsonResult.success();
        } catch (BusinessException e) {
            e.printStackTrace();
            return JsonResult.error(e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return JsonResult.error("系统异常");
        }
    }



}
